package com.colorlight.cloud.mqtt.base.entity;

import lombok.*;


/**
 * @author Demon
 * 5大属性
 * QoS  默认值为 1
 * Retained（是否保留消息）：默认值为 false
 * Topic（主题）：没有固定的默认值，需要根据实际需求指定主题。
 * Message ID（消息标识）：没有固定的默认值，一般由 MQTT 客户端自动生成或根据需求设置。
 * 重试标识（Retries Exhausted）：默认值为 false（MqttHeaders.RETRIES_EXHAUSTED_FALSE）。
 */

@Data
@Builder
@NoArgsConstructor
public class IMqttHeaders<T> {
	
	private String topic;
	private QosEnum qos;
	private T message;
	private Boolean retriesExhausted;
	private String messageId;
	private Boolean retained;
	
	public IMqttHeaders(String topic, T message) {
		this(topic, QosEnum.QOS_O, message, null, null, null);
	}
	
	public IMqttHeaders(String topic, Integer qos, T message) {
		this(topic, QosEnum.getQos(qos), message, null, null, null);
	}
	
	public IMqttHeaders(
			String topic,
			QosEnum qos,
			T message,
			Boolean retriesExhausted,
			String messageId,
			Boolean retained) {
		if (topic == null || topic.isEmpty()) {
			throw new NullPointerException("主题不为null");
		}
		this.topic = topic;
		if (qos == null) {
			this.qos = QosEnum.QOS_O;
		}
		if (Boolean.TRUE.equals(retained)) {
			this.retained = false;
		}
		if (Boolean.TRUE.equals(retriesExhausted)) {
			this.retriesExhausted = false;
		}
		if (messageId == null || messageId.isEmpty()) {
			this.message = message;
		}
		this.qos = qos;
	}
}
